package com.yxw.live_vod_boot.service.impl;



import lombok.extern.slf4j.Slf4j;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import com.yxw.yxnet_cd_center.common.utils.BaseDateTime;
import org.springframework.transaction.annotation.Transactional;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.hutool.core.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yxw.live_vod_boot.entity.YxLiveUserWatchDurationEntity;
import com.yxw.live_vod_boot.dto.YxLiveUserWatchDurationDTO;
import com.yxw.live_vod_boot.dto.YxLiveUserWatchDurationAddDTO;
import com.yxw.live_vod_boot.dto.YxLiveUserWatchDurationQueryDTO;
import com.yxw.live_vod_boot.mapper.YxLiveUserWatchDurationMapper;
import com.yxw.live_vod_boot.service.IYxLiveUserWatchDurationService;



/*** 
*@author Jiaxu.Huang
*@date 2023/12/27 16:58:09
*@update 2023/12/27 16:58:09
**/
@Slf4j
@Service
//public class YxLiveUserWatchDurationServiceImpl  extends ServiceImpl<YxLiveUserWatchDurationMapper, YxLiveUserWatchDurationEntity> implements IYxLiveUserWatchDurationService{
public class YxLiveUserWatchDurationServiceImpl  implements IYxLiveUserWatchDurationService{
    @Autowired
    private YxLiveUserWatchDurationMapper oYxLiveUserWatchDurationMapper;
    /*** 
    * 新增用户观看直播时长超过20分钟的店铺
    * @param oYxLiveUserWatchDurationDTO
    * @return BaseResult
    **/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public BaseResult insertYxLiveUserWatchDuration(YxLiveUserWatchDurationAddDTO oYxLiveUserWatchDurationAddDTO)
    {
        YxLiveUserWatchDurationEntity oYxLiveUserWatchDurationEntity = new YxLiveUserWatchDurationEntity();
        BeanUtil.copyProperties(oYxLiveUserWatchDurationAddDTO, oYxLiveUserWatchDurationEntity);
        oYxLiveUserWatchDurationEntity.setCreateTime(System.currentTimeMillis());
        oYxLiveUserWatchDurationEntity.setUpdateTime(oYxLiveUserWatchDurationEntity.getCreateTime());
        oYxLiveUserWatchDurationMapper.insert(oYxLiveUserWatchDurationEntity);
        //oYxLiveUserWatchDurationDTO.setId(oYxLiveUserWatchDurationEntity.getId());
        return BaseResult.success(oYxLiveUserWatchDurationEntity);
    }
    /*** 
    * 修改用户观看直播时长超过20分钟的店铺
    * @param oYxLiveUserWatchDurationDTO
    * @return BaseResult
    **/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public BaseResult updateYxLiveUserWatchDurationById(YxLiveUserWatchDurationDTO oYxLiveUserWatchDurationDTO)
    {
        YxLiveUserWatchDurationEntity oYxLiveUserWatchDurationEntity = new YxLiveUserWatchDurationEntity();
        BeanUtil.copyProperties(oYxLiveUserWatchDurationDTO, oYxLiveUserWatchDurationEntity);
        oYxLiveUserWatchDurationEntity.setUpdateTime(System.currentTimeMillis());
        oYxLiveUserWatchDurationMapper.updateById(oYxLiveUserWatchDurationEntity);
        return BaseResult.success();
    }
    /*** 
    * 删除用户观看直播时长超过20分钟的店铺
    * @param id
    * @return BaseResult
    **/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public BaseResult deleteYxLiveUserWatchDurationById(Long id)
    {
        if(ObjectUtil.isEmpty(id))
        {
            return BaseResult.failed("Id不能为空值");
        }
        oYxLiveUserWatchDurationMapper.deleteById(id);
        return BaseResult.success();
    }
    /*** 
    * 根据id查找用户观看直播时长超过20分钟的店铺
    * @param id
    * @return YxLiveUserWatchDurationEntity
    **/
    @Override
    public YxLiveUserWatchDurationEntity selectYxLiveUserWatchDurationById(Long id)
    {
        if(ObjectUtil.isEmpty(id))
        {
            return null;
        }
        return oYxLiveUserWatchDurationMapper.selectById(id);
    }
    /*** 
    * 自定义查询用户观看直播时长超过20分钟的店铺
    * @param oYxLiveUserWatchDurationDTO
    * @return List<YxLiveUserWatchDurationEntity>
    **/
    @Override
    public List<YxLiveUserWatchDurationEntity> selectYxLiveUserWatchDurationList(YxLiveUserWatchDurationQueryDTO oYxLiveUserWatchDurationQueryDTO)
    {
        QueryWrapper<YxLiveUserWatchDurationEntity> oYxLiveUserWatchDurationQueryWrapper = new QueryWrapper();
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getId()),"id",oYxLiveUserWatchDurationQueryDTO.getId());
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getUserInnerId()),"user_inner_id",oYxLiveUserWatchDurationQueryDTO.getUserInnerId());
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getLiveShopId()),"live_shop_id",oYxLiveUserWatchDurationQueryDTO.getLiveShopId());
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getLiveId()),"live_id",oYxLiveUserWatchDurationQueryDTO.getLiveId());
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getMaxDuration()),"max_duration",oYxLiveUserWatchDurationQueryDTO.getMaxDuration());
        oYxLiveUserWatchDurationQueryWrapper.ge(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getCreateTimeStart()),"create_time",oYxLiveUserWatchDurationQueryDTO.getCreateTimeStart());
        oYxLiveUserWatchDurationQueryWrapper.le(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getCreateTimeEnd()),"create_time",oYxLiveUserWatchDurationQueryDTO.getCreateTimeEnd());
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getUpdateTime()),"update_time",oYxLiveUserWatchDurationQueryDTO.getUpdateTime());
        //List<YxLiveUserWatchDurationEntity> oListYxLiveUserWatchDuration = oYxLiveUserWatchDurationMapper.selectList(oYxLiveUserWatchDurationQueryWrapper);
        //return Res.ok(oListYxLiveUserWatchDuration);
        return  oYxLiveUserWatchDurationMapper.selectList(oYxLiveUserWatchDurationQueryWrapper);
    }
    /*** 
    * 自定义统计用户观看直播时长超过20分钟的店铺
    * @param oYxLiveUserWatchDurationEntity
    * @return Integer
    **/
    @Override
    public Integer selectYxLiveUserWatchDurationCount(YxLiveUserWatchDurationQueryDTO oYxLiveUserWatchDurationQueryDTO)
    {
        QueryWrapper<YxLiveUserWatchDurationEntity> oYxLiveUserWatchDurationQueryWrapper = new QueryWrapper();
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getId()),"id",oYxLiveUserWatchDurationQueryDTO.getId());
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getUserInnerId()),"user_inner_id",oYxLiveUserWatchDurationQueryDTO.getUserInnerId());
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getLiveShopId()),"live_shop_id",oYxLiveUserWatchDurationQueryDTO.getLiveShopId());
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getLiveId()),"live_id",oYxLiveUserWatchDurationQueryDTO.getLiveId());
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getMaxDuration()),"max_duration",oYxLiveUserWatchDurationQueryDTO.getMaxDuration());
        oYxLiveUserWatchDurationQueryWrapper.ge(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getCreateTimeStart()),"create_time",oYxLiveUserWatchDurationQueryDTO.getCreateTimeStart());
        oYxLiveUserWatchDurationQueryWrapper.le(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getCreateTimeEnd()),"create_time",oYxLiveUserWatchDurationQueryDTO.getCreateTimeEnd());
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getUpdateTime()),"update_time",oYxLiveUserWatchDurationQueryDTO.getUpdateTime());
        return oYxLiveUserWatchDurationMapper.selectCount(oYxLiveUserWatchDurationQueryWrapper);
    }
    /*** 
    * 自定义分页查询用户观看直播时长超过20分钟的店铺
    * @param currentPage 当前页
    * @param pageSize 分页大小
    * @param oYxLiveUserWatchDurationEntity
    * @return Page
    **/
    @Override
    public Page selectYxLiveUserWatchDurationPage(int currentPage,int pageSize,YxLiveUserWatchDurationQueryDTO oYxLiveUserWatchDurationQueryDTO)
    {
        if(currentPage <= 1)
        {
            currentPage = 1;
        }
        if(pageSize <= 0)
        {
            pageSize = 10;
        }
        Page<YxLiveUserWatchDurationEntity> pageParams = new Page<>(currentPage,pageSize);
        QueryWrapper<YxLiveUserWatchDurationEntity> oYxLiveUserWatchDurationQueryWrapper = new QueryWrapper();
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getId()),"id",oYxLiveUserWatchDurationQueryDTO.getId());
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getUserInnerId()),"user_inner_id",oYxLiveUserWatchDurationQueryDTO.getUserInnerId());
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getLiveShopId()),"live_shop_id",oYxLiveUserWatchDurationQueryDTO.getLiveShopId());
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getLiveId()),"live_id",oYxLiveUserWatchDurationQueryDTO.getLiveId());
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getMaxDuration()),"max_duration",oYxLiveUserWatchDurationQueryDTO.getMaxDuration());
        oYxLiveUserWatchDurationQueryWrapper.ge(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getCreateTimeStart()),"create_time",oYxLiveUserWatchDurationQueryDTO.getCreateTimeStart());
        oYxLiveUserWatchDurationQueryWrapper.le(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getCreateTimeEnd()),"create_time",oYxLiveUserWatchDurationQueryDTO.getCreateTimeEnd());
        oYxLiveUserWatchDurationQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveUserWatchDurationQueryDTO.getUpdateTime()),"update_time",oYxLiveUserWatchDurationQueryDTO.getUpdateTime());
        return oYxLiveUserWatchDurationMapper.selectPage(pageParams, oYxLiveUserWatchDurationQueryWrapper);
    }
}
    

